package com.burstly.lib.component.networkcomponent.burstly.html;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;

public class CloseableContainer<T extends View> extends FrameLayout
  implements View.OnClickListener, Runnable, ICloseControl
{
  public static final String BOTTOM_CENTER = "bottom-center";
  public static final String BOTTOM_LEFT = "bottom-left";
  public static final String BOTTOM_RIGHT = "bottom-right";
  public static final String CENTER = "center";
  private static final int CLOSE_AREA_SIZE = 50;
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String TAG = CloseableContainer.class.getSimpleName();
  public static final String TOP_CENTER = "top-center";
  public static final String TOP_LEFT = "top-left";
  public static final String TOP_RIGHT = "top-right";
  private long mCloseAllowedAfter;
  private final ImageView mCloseArea;
  private View.OnClickListener mCloseClickListener;
  private T mContainedView;
  private long mShowCloseButtonDelay;
  private Handler mUiHandler;

  public CloseableContainer(Context paramContext)
  {
    super(paramContext);
    this.mCloseArea = new ImageView(paramContext);
    this.mCloseArea.setOnClickListener(this);
    setShowCloseIndicator(true, "top-right");
    addView(this.mCloseArea);
  }

  private boolean isBackKeyAllowed()
  {
    return System.currentTimeMillis() > this.mCloseAllowedAfter;
  }

  @TargetApi(16)
  private void setCloseAreaBackground(Drawable paramDrawable)
  {
    if (Build.VERSION.SDK_INT < 16)
    {
      this.mCloseArea.setBackgroundDrawable(paramDrawable);
      return;
    }
    this.mCloseArea.setBackground(paramDrawable);
  }

  public boolean dispatchKeyEvent(KeyEvent paramKeyEvent)
  {
    if ((paramKeyEvent.getKeyCode() == 4) && (!isBackKeyAllowed()))
      return true;
    return super.dispatchKeyEvent(paramKeyEvent);
  }

  protected ImageView getCloseArea()
  {
    return this.mCloseArea;
  }

  public View.OnClickListener getCloseClickListener()
  {
    return this.mCloseClickListener;
  }

  public T getContainedView()
  {
    return this.mContainedView;
  }

  public long getShowCloseButtonDelay()
  {
    return this.mShowCloseButtonDelay;
  }

  protected void onAttachedToWindow()
  {
    super.onAttachedToWindow();
    if (this.mShowCloseButtonDelay > 0L)
    {
      if (this.mUiHandler == null)
        this.mUiHandler = new Handler();
      this.mCloseAllowedAfter = (System.currentTimeMillis() + this.mShowCloseButtonDelay);
      this.mUiHandler.postDelayed(this, this.mShowCloseButtonDelay);
    }
  }

  public void onClick(View paramView)
  {
    if (this.mCloseClickListener == null)
    {
      LOG.logDebug(TAG, "Close action is not defined", new Object[0]);
      return;
    }
    this.mCloseClickListener.onClick(this.mContainedView);
  }

  public void putIntoContainer(T paramT)
  {
    this.mContainedView = paramT;
    removeView(this.mCloseArea);
    int i = Utils.getFillparentValue();
    addView(paramT, new FrameLayout.LayoutParams(i, i, 17));
    addView(this.mCloseArea);
  }

  public void run()
  {
    this.mCloseArea.setVisibility(0);
  }

  public void setCloseAreaGravity(String paramString)
  {
    FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams(50, 50);
    if ("top-left".equals(paramString))
      localLayoutParams.gravity = 51;
    while (true)
    {
      this.mCloseArea.setLayoutParams(localLayoutParams);
      return;
      if ("bottom-left".equals(paramString))
        localLayoutParams.gravity = 83;
      else if ("bottom-right".equals(paramString))
        localLayoutParams.gravity = 85;
      else if ("center".equals(paramString))
        localLayoutParams.gravity = 17;
      else if ("bottom-center".equals(paramString))
        localLayoutParams.gravity = 81;
      else if ("top-center".equals(paramString))
        localLayoutParams.gravity = 49;
      else
        localLayoutParams.gravity = 53;
    }
  }

  public void setCloseClickListener(View.OnClickListener paramOnClickListener)
  {
    this.mCloseClickListener = paramOnClickListener;
  }

  public void setShowCloseButtonDelay(long paramLong)
  {
    if (paramLong > 0L)
    {
      this.mShowCloseButtonDelay = paramLong;
      this.mCloseArea.setVisibility(8);
    }
  }

  public void setShowCloseIndicator(boolean paramBoolean)
  {
    setShowCloseIndicator(paramBoolean, "top-right");
  }

  public void setShowCloseIndicator(boolean paramBoolean, String paramString)
  {
    if (paramBoolean)
    {
      this.mCloseArea.setAdjustViewBounds(true);
      setCloseAreaBackground(Utils.getCloseImage(getContext()));
      setCloseAreaGravity(paramString);
      return;
    }
    this.mCloseArea.setAdjustViewBounds(false);
    setCloseAreaBackground(null);
  }

  public void showClose(boolean paramBoolean)
  {
    setShowCloseIndicator(paramBoolean);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.CloseableContainer
 * JD-Core Version:    0.6.2
 */